# -*- coding: UTF-8 -*-
from Queue import Queue
from logger import logger

class GlobalMSG:
    receive_msg_queue = Queue()
    cmd_msg_queue  = Queue()


def global_set_receivemsg(msg_data):
    GlobalMSG.receive_msg_queue.put(msg_data)

def global_get_receivemsg():
    msg_data = []
    if not GlobalMSG.receive_msg_queue.empty():
        msg_data = GlobalMSG.receive_msg_queue.get(False)
    return msg_data


def global_set_cmdmsg(msg_data):
    GlobalMSG.cmd_msg_queue.put(msg_data)

def global_get_cmdmsg():
    msg_data = []
    #if not GlobalMSG.cmd_msg_queue.empty():
    msg_data = GlobalMSG.cmd_msg_queue.get(True)
    return msg_data

def system_post_cmd(networkid,lampid, protocoltype, address, cmd_client, cmd_type, senddata):
    udpmsg = {
        'networkid': networkid,
        'lampid': lampid,
        'protocoltype': protocoltype,
        'address': address,
        'cmd_client': cmd_client,
        'cmd_type': cmd_type,
        'senddata': senddata
    }
    logger.info(str(udpmsg))
    global_set_cmdmsg(udpmsg)
